#
# $Id: Makefile,v 1.4 2004/05/17 08:49:11 pgusak Exp $
#

CC   = gcc
LEX  = lex
PERL = perl
YACC = byacc

# -v gives verbose output.
YFLAGS = -d -p ws_yy_

SRC     = source
LIBS    = -lexpat
CFLAGS  = -O2 -static
LDFLAGS =


wmlscriptsrcs = $(wildcard $(SRC)/*.c)
wmlscriptobjs = $(wmlscriptsrcs:.c=.o)

all: wmlsc.exe

clean:
	@rm -f $(SRC)/make-op-table $(SRC)/wsopcodes.h $(SRC)/*.o

veryclean: clean
	@rm -f wmlsc.exe

.y.c:
	$(YACC) $(YFLAGS) $< && mv y.tab.c $*.c
	if test -f y.tab.h; then \
	if cmp -s y.tab.h $*.h; then rm y.tab.h; else mv y.tab.h $*.h; fi; \
	else :; fi

.c.o:
	$(CC) $(CFLAGS) -o $@ -c $<

$(SRC)/wsgram.h: $(SRC)/wsgram.c

$(SRC)/make-op-table: $(SRC)/make-op-table.in
	sed 's%@PERLPROG@%/bin/$(PERL)%g' $< > $@
	chmod a+x $@

$(SRC)/wsopcodes.h: $(SRC)/make-op-table $(SRC)/wsasm.h
	$(SRC)/make-op-table $(SRC)/wsasm.h > $@

wmlsc.exe: $(SRC)/wsopcodes.h $(wmlscriptobjs)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(wmlscriptobjs) $(LIBS)

